<template>
	<view class="main">
		<view class="container">
		    <view  class="preview" @click="shouldChooseImage ? chooseImage() : null">
		      <image v-if="imageUrl" :src="imageUrl" mode="aspectFill"></image>
			  <view class="inner" v-else >
				  <view v-if="(status == 1||hasEnterprise == 1)&&!imageUrl" class="innerif" style="color: white;background-color: #5ac725; width:600rpx;height: 300rpx;display: flex; align-items: center; justify-content: center;font-size: 50rpx;">
				  	<text>您已通过审核</text>
				  </view>
				  <view  v-else style="display: flex;flex-direction: column;">
				  	<text  class="add">+</text>
				  	 <text>
				  						   请上传营业执照
				  	 </text>
				  </view>
			  </view>
		    </view>
			<view v-if="isEnterprising == 0||status == 0"  class="send-button">
				<button v-if="imageUrl&&hasEnterprise == 0" @click="showuploadImage? uploadImage() :null">确认上传</button>
			</view>
			<view v-if="isEnterprising == 1&&status == 2" class="toexa">
				<button>审核中</button>
			</view>
			<view v-if="status == 1||hasEnterprise == 1" class="tosuccess">
				<button>认证成功</button>
			</view>
			<view class="autloading">
				<u-loading-icon mode="circle" :show="!showuploadImage"></u-loading-icon> 
			</view>
		  </view>
		  
	</view>
</template>

<script>
import Index from "@/common/index-model.js"	
import fun from "@/common/publicFun.js"	
let index = new Index()
let that = this
export default {
	data() {
		return {
			 imageUrl: '', // 用于预览图片的地址
			 tempFilePath: '', // 用于保存选择的图片文件路径
			 status:'',//审核状态
			 isEnterprising:'',//是否正在审核
			 hasEnterprise:'',//审核结果
			 shouldChooseImage:true,
			 showuploadImage:true,
			//
			inputForm:{
				id:'',
				clicense:'',
				entName:'',
				regNo:'',
				realName:'',
				idNo:''
			},
			status:0
		}
	},
	methods: {	
		// 选择图片
		chooseImage() {
		  uni.chooseImage({
		    count: 1, // 最多选择一张图片
		    sizeType: ['compressed'], // 压缩图片
		    sourceType: ['album', 'camera'], // 选择图片的来源，相册或者相机
		    success: (res) => {
		      this.tempFilePath = res.tempFilePaths;
		      this.imageUrl = res.tempFilePaths[0]; // 显示选择的图片
		    }
		  });
		},
		// 上传图片
		uploadImage() {
			index.show_tips('上传中')
			console.log("上传了图片",this.tempFilePath)
			this.showuploadImage = false
		  // 这里可以添加上传图片的逻辑，上传到服务器等
		  uni.uploadFile({
		    url: index.img_url + 'client/public/upload?type=enterpriseLicense&file=' + this.tempFilePath,
		    filePath: this.tempFilePath[0],
		    name: 'file',
		    formData: {
		      // 可以添加额外的表单数据
		    },
			header: {
				'X-Access-Token': uni.getStorageSync('token'),
				'Login-Type': 'client'
			},
		    success: (res) => {
		      // 上传成功的处理逻辑
		      console.log('上传成功', res.data);
			  this.showuploadImage = true
		      // 根据实际需求处理上传成功后的逻辑
			  let imgurl = JSON.parse(res.data).result.url
			  this.inputForm.clicense = imgurl
			  index.getPublicUserMember(this.inputForm,'/client/realauth/submitEnterpriseNew','post',res=>{
			  	if(res.data.code == 200 && res.data.success){
			  		index.show_tips('已提交，等待审核')
					this.getState()
					this.shouldChooseImage = false
			  	}else{
			  		index.show_tips(res.data.message);
					console.log(res.data.message)
			  		return false
			  	}
			  })
			  
		    },
		    fail: (err) => {
		      // 上传失败的处理逻辑
		      console.error('上传失败', err);
		    }
		  });
		}
		,
		getPostInfo() {
			index.getPublicUserMember({},'/client/enterprise/info/detailNew','get',res=>{
				console.log(res.data.success,"结果")
				if(res.data.result.status != 0){
					this.shouldChooseImage = false
					this.imageUrl = res.data.result.clicense
				
				}
					this.inputForm.id = res.data.result.id
				
			})
		},
		getState() {
			index.getPublicUserMember({},'/client/enterprise/info/enterpriseStatus','get',res=>{
				console.log(res.data.result)
				this.status = res.data.result.status
				this.isEnterprising = res.data.result.isEnterprising
				this.hasEnterprise = res.data.result.hasEnterprise
				if(res.data.result.status == 0){
					index.show_tips('认证失败,请重新上传')
					this.shouldChooseImage = true
					this.imageUrl =""
				}
				
			})
		}
	},
	onLoad() {
		this.imageUrl =""
		this.getPostInfo()
		this.getState()
	},

}
</script>



<style>
@import url("@/static/css/publics.css");
@import url("@/static/css/myeditphone.css");
</style>
